import Vue from 'vue';
import Vuex from 'vuex'
Vue.use(Vuex)
import request from '../common/request';
const store = new Vuex.Store({
	state: {
		user: {}, // 用户信息
		tabbar: [
			{
				iconPath: "/static/tabbar/1.png",
				selectedIconPath: "/static/tabbar/2.png",
				text: 'AI视频创作',
				customIcon: false,
				path: "/pages/videoMaker/index"
			},
			// {
			// 	iconPath: "/static/tabbar/3.png",
			// 	selectedIconPath: "/static/tabbar/4.png",
			// 	text: 'AI轻创业联盟',
			// 	customIcon: false,
			// 	path: "/pages/entrepreneurship/index"
			// },
			{
				iconPath: "/static/tabbar/5.png",
				selectedIconPath: "/static/tabbar/6.png",
				text: 'AI对话',
				customIcon: false,
				path: "/pages/weChat/index"
			},
			{
				iconPath: "/static/tabbar/7.png",
				selectedIconPath: "/static/tabbar/8.png",
				text: '我的',
				customIcon: false,
				path: "/pages/mine/index"
			}
		],
		tabbarCurrent: 0,
		show: false,
		isLogin: false
	},
	// 修改store中的值唯一的方法就是提交mutation来修改
	mutations: {
		/**
		 * 设置状态
		 * @param {Object} state 状态对象
		 * @param {Object} provider 传入值
		 */
		// 用户信息
		userState(state, provider) {
			state.user = provider
		},

		userIsLogin(state, provider) {
			state.isLogin = provider
		},
	},
	actions: {
		// 用户信息
		getUser(context){
			request("/aiet-user-center/user/info", {}, "GET").then(res=>{
				console.log("用户信息", res.data)
				if(res.code===200) context.commit("userState", res.data)
				if(res.code===500 && res.msg=="token无效") context.commit("userIsLogin", false)
			})
		},
	}
})

export default store
